#include <QIcon>
#include <QDesktopServices>
#include <QUrl>
#include "intro_page_style.h"
#include "ui_intro_page_style.h"
#include "globaldata.h"

IntroPageStyle::IntroPageStyle(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::IntroPageStyle)
{
    ui->setupUi(this);
    initUI();
}

IntroPageStyle::~IntroPageStyle()
{
    delete ui;
}

void IntroPageStyle::initUI()
{
    ui->m_pKylinPic->setStyleSheet("border-image:url(:/data/banner.png);border:0px;");

    QPalette peMid;
    QColor colorMid = palette().color(QPalette::Mid);
    peMid.setColor(QPalette::Text,colorMid);
    ui->m_pMoreInfoLink_1->setText(tr("Click "));
    ui->m_pMoreInfoLink_1->setPalette(peMid);

    // QPalette peHighlight;
    // QColor colorHighlight = palette().color(QPalette::Link);
    // peHighlight.setColor(QPalette::Text, colorHighlight);
    // ui->m_pMoreInfoLink_2->setPalette(peHighlight);

    ui->m_pMoreInfoLink_2->setCursor(QCursor(Qt::PointingHandCursor));
    ui->m_pMoreInfoLink_2->setText("<a href = 'https://www.kylinos.cn/support/problem.html'>" + tr("to know more about support") + "</a>");
    ui->m_pMoreInfoLink_2->installEventFilter(this);

    ui->m_pMoreInfoLink_3->setText(tr("，to KylinOS Official Web"));
    ui->m_pMoreInfoLink_3->setPalette(peMid);

    ui->m_pPageTitle->setText(tr("You can get your answers through the ways below"));//"用户可通过以下方式寻求技术支持和服务");
    ui->m_pPageTitle->setPalette(peMid);

    ui->m_pOnline_1->setProperty("useIconHighlightEffect", 0x2);
    ui->m_pOnline_1->setProperty("isWindowButton", 0x01);
    ui->m_pOnline_1->setFlat(true);
    ui->m_pOnline_1->setIcon(QIcon::fromTheme("ukui-wechat-symbolic"));
    ui->m_pOnline_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->m_pOnline_2->adjustSize();
    ui->m_pOnline_2->setText(tr("Official WeChat"));//"企业微信");
    ui->m_pOnline_2->setAlignment(Qt::AlignLeft);
    ui->m_pOnline_2->setAlignment(Qt::AlignVCenter);
    ui->m_pOnline_3->adjustSize();
    ui->m_pOnline_3->setText(tr("Add our Team's WeChat"));
    ui->m_pOnline_3->setAlignment(Qt::AlignLeft);
    ui->m_pOnline_3->setAlignment(Qt::AlignVCenter);
    ui->m_pOnline_3->setPalette(peMid);
    ui->m_pOnline_4->adjustSize();
    ui->m_pOnline_4->setText(tr("Get an online response."));
    ui->m_pOnline_4->setAlignment(Qt::AlignLeft);
    ui->m_pOnline_4->setAlignment(Qt::AlignVCenter);
    ui->m_pOnline_4->setPalette(peMid);

    ui->m_pTelphone_1->setProperty("useIconHighlightEffect", 0x2);
    ui->m_pTelphone_1->setProperty("isWindowButton", 0x01);
    ui->m_pTelphone_1->setFlat(true);
    ui->m_pTelphone_1->setIcon(QIcon::fromTheme("audio-headset-symbolic"));
    ui->m_pTelphone_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->m_pTelphone_2->adjustSize();
    ui->m_pTelphone_2->setText(tr("Online"));//"企业微信");
    ui->m_pTelphone_2->setAlignment(Qt::AlignLeft);
    ui->m_pTelphone_2->setAlignment(Qt::AlignVCenter);
    ui->m_pTelphone_3->adjustSize();
    ui->m_pTelphone_3->setPalette(peMid);
    ui->m_pTelphone_3->setText(tr("Leave message"));
    ui->m_pTelphone_3->setAlignment(Qt::AlignLeft);
    ui->m_pTelphone_3->setAlignment(Qt::AlignVCenter);
    ui->m_pTelphone_4->adjustSize();
    ui->m_pTelphone_4->setText(tr("to get support."));
    ui->m_pTelphone_4->setAlignment(Qt::AlignLeft);
    ui->m_pTelphone_4->setAlignment(Qt::AlignVCenter);
    ui->m_pTelphone_4->setPalette(peMid);

    ui->m_pMail_1->setProperty("useIconHighlightEffect", 0x2);
    ui->m_pMail_1->setProperty("isWindowButton", 0x01);
    ui->m_pMail_1->setFlat(true);
    ui->m_pMail_1->setIcon(QIcon::fromTheme("mail-read-symbolic"));
    ui->m_pMail_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->m_pMail_2->adjustSize();
    ui->m_pMail_2->setText(tr("Mail"));
    ui->m_pMail_2->setAlignment(Qt::AlignLeft);
    ui->m_pMail_2->setAlignment(Qt::AlignVCenter);
    ui->m_pMail_3->adjustSize();
    ui->m_pMail_3->setText(tr("Send mail to"));
    ui->m_pMail_3->setAlignment(Qt::AlignLeft);
    ui->m_pMail_3->setAlignment(Qt::AlignVCenter);
    ui->m_pMail_3->setPalette(peMid);
    ui->m_pMail_4->adjustSize();
    ui->m_pMail_4->setText(tr("get support."));
    ui->m_pMail_4->setAlignment(Qt::AlignLeft);
    ui->m_pMail_4->setAlignment(Qt::AlignVCenter);
    ui->m_pMail_4->setPalette(peMid);

    ui->m_pWeChat_1->setProperty("useIconHighlightEffect", 0x2);
    ui->m_pWeChat_1->setProperty("isWindowButton", 0x01);
    ui->m_pWeChat_1->setFlat(true);
    ui->m_pWeChat_1->setIcon(QIcon::fromTheme("call-stop-symbolic"));
    ui->m_pWeChat_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->m_pWeChat_2->adjustSize();
    ui->m_pWeChat_2->setText(tr("Telephone"));
    ui->m_pWeChat_2->setAlignment(Qt::AlignLeft);
    ui->m_pWeChat_2->setAlignment(Qt::AlignVCenter);
    ui->m_pWeChat_3->adjustSize();
    ui->m_pWeChat_3->setText(tr("5*8 hours hotline."));
    ui->m_pWeChat_3->setAlignment(Qt::AlignLeft);
    ui->m_pWeChat_3->setAlignment(Qt::AlignVCenter);
    ui->m_pWeChat_3->setPalette(peMid);
    
    // ui->m_pWeChat_4->adjustSize();
    // ui->m_pWeChat_4->setText(tr(""));
    // ui->m_pWeChat_4->setAlignment(Qt::AlignLeft);
    // ui->m_pWeChat_4->setAlignment(Qt::AlignVCenter);
    // ui->m_pWeChat_4->setPalette(peMid);

    ui->m_pDIY_1->setProperty("useIconHighlightEffect", 0x2);
    ui->m_pDIY_1->setProperty("isWindowButton", 0x01);
    ui->m_pDIY_1->setFlat(true);
    ui->m_pDIY_1->setIcon(QIcon::fromTheme("ukui-self-help-symbolic"));
    ui->m_pDIY_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->m_pDIY_2->adjustSize();
    ui->m_pDIY_2->setText(tr("Guidance"));
    ui->m_pDIY_2->setAlignment(Qt::AlignLeft);
    ui->m_pDIY_2->setAlignment(Qt::AlignVCenter);
    ui->m_pDIY_3->adjustSize();
    ui->m_pDIY_3->setText(tr("Check Manuals to solve"));
    ui->m_pDIY_3->setAlignment(Qt::AlignLeft);
    ui->m_pDIY_3->setAlignment(Qt::AlignVCenter);
    ui->m_pDIY_3->setPalette(peMid);
    ui->m_pDIY_4->adjustSize();
    ui->m_pDIY_4->setText(tr("the problem."));
    ui->m_pDIY_4->setAlignment(Qt::AlignLeft);
    ui->m_pDIY_4->setAlignment(Qt::AlignVCenter);
    ui->m_pDIY_4->setPalette(peMid);
}
void IntroPageStyle::changeFont(QFont curFont)
{
    QFont smallFont = GlobalData::getInstance()->getFontSize12px();
    QFont normalFont = curFont;
    //小字
    ui->m_pMoreInfoLink_1->setFont(smallFont);
    ui->m_pMoreInfoLink_2->setFont(smallFont);
    ui->m_pMoreInfoLink_3->setFont(smallFont);

    ui->m_pPageTitle->setFont(smallFont);
    ui->m_pOnline_3->setFont(smallFont);
    ui->m_pOnline_4->setFont(smallFont);
    ui->m_pTelphone_3->setFont(smallFont);
    ui->m_pTelphone_4->setFont(smallFont);
    ui->m_pMail_3->setFont(smallFont);
    ui->m_pMail_4->setFont(smallFont);
    ui->m_pWeChat_3->setFont(smallFont);
    // ui->m_pWeChat_4->setFont(smallFont);
    ui->m_pDIY_3->setFont(smallFont);
    ui->m_pDIY_4->setFont(smallFont);
    //中等字
    ui->m_pOnline_2->setFont(normalFont);
    ui->m_pTelphone_2->setFont(normalFont);
    ui->m_pMail_2->setFont(normalFont);
    ui->m_pWeChat_2->setFont(normalFont);
    ui->m_pDIY_2->setFont(normalFont);
}
bool IntroPageStyle::eventFilter(QObject *obj, QEvent *ev)
{
    if(obj == ui->m_pMoreInfoLink_2)
    {
        if(ev->type() == QEvent::MouseButtonPress)
        {
            /* SDK功能点： 跳转官网主页*/
            GlobalData::SDKPointJumpOfficicalWebsite();

            QDesktopServices::openUrl(QUrl("https://www.kylinos.cn/support/problem.html"));

        }
    }

    return QWidget::eventFilter(obj,ev);
}
